package org.come.thread;

import com.tool.ModerateTask.Hero;
import com.tool.ModerateTask.Task;
import com.tool.image.ImageMixDeal;
import com.tool.imagemonitor.ScriptTask;
import come.tool.Fighting.FightingMixDeal;
import come.tool.handle.HandleState;
import org.come.Frame.ZhuFrame;
import org.come.bean.RoleShow;

import java.util.HashMap;

public class YuWaiRunnable implements Runnable{

    HashMap<String, Integer> countMap = new HashMap<>();

    @Override
    public void run() {
        try {
            while (true){

                Thread.sleep(1000L);

                Task task = Hero.hero.getTaskSet(105);
                if(task != null){
                    RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
                    Long mapid = roleShow.getMapid();
                    int x = roleShow.getX();
                    int y = roleShow.getY();

                    String key = mapid.toString() + "_" + x + "_" + y;

                    if(FightingMixDeal.State!= HandleState.USUAL){
                        countMap.clear();
                        Thread.sleep(1000L);
                    }else{
                        if(mapid == 3180||mapid == 3208||mapid == 3209||mapid == 3210||mapid==3305||mapid == 3307||mapid == 3308 || mapid == 3309){
                            Integer integer = countMap.get(key);

                            if(integer !=null && integer >= 30){
                                countMap.clear();
                                String[] v= new String[]{"1207", "4830", "2770", "400024", "999"};
                                TimeControlRunnable.addTask(new ScriptTask(v,105));
                            }

                            if(countMap.containsKey(key)){
                                countMap.put(key, countMap.get(key) + 1);
                            }else{
                                countMap.put(key, 1);
                            }

                            if(integer!= null && integer%10==0){
                                ZhuFrame.getZhuJpanel().addPrompt2("域外任务可能卡住了，倒计时开始#R30#Y秒开始自动任务，当前等待 = #G" + integer + " #Y秒");
                            }

//                            //system.out.println("integer === " + integer);
                        }
                    }
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
